<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Vue哪儿网App实战,">










<meta name="description" content="本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：入门视频：《vue2.5入门》 http://www.imooc.com/learn/980实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 https://coding.imooc.com/class/chapter/203.html 本文为实战篇的第六章，主要讲解开发去哪儿网App实站环境准备 本文对应官网文档地">
<meta name="keywords" content="Vue哪儿网App实战">
<meta property="og:type" content="article">
<meta property="og:title" content="【实战篇——第六章】Vue2.5入门到实战开发去哪儿网App——实站环境准备">
<meta property="og:url" content="https://aiolos123.gitee.io/blog/2019/09/27/vue-learning-step-by-step-8/index.html">
<meta property="og:site_name" content="Aiolos">
<meta property="og:description" content="本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：入门视频：《vue2.5入门》 http://www.imooc.com/learn/980实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 https://coding.imooc.com/class/chapter/203.html 本文为实战篇的第六章，主要讲解开发去哪儿网App实站环境准备 本文对应官网文档地">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190927125507425.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190927125733996.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190927130118079.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190927131201954.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190927131440243.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929054501970.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929055844938.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929061234843.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929062406951.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929062817594.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929063424408.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190929132152629.jpg">
<meta property="og:updated_time" content="2019-10-10T06:09:23.008Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【实战篇——第六章】Vue2.5入门到实战开发去哪儿网App——实站环境准备">
<meta name="twitter:description" content="本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：入门视频：《vue2.5入门》 http://www.imooc.com/learn/980实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 https://coding.imooc.com/class/chapter/203.html 本文为实战篇的第六章，主要讲解开发去哪儿网App实站环境准备 本文对应官网文档地">
<meta name="twitter:image" content="https://aiolos123.gitee.io/blog/images/20190927125507425.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://aiolos123.gitee.io/blog/2019/09/27/vue-learning-step-by-step-8/">





  <title>【实战篇——第六章】Vue2.5入门到实战开发去哪儿网App——实站环境准备 | Aiolos</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Aiolos</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录我的成长点滴</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://aiolos123.gitee.io/blog/blog/2019/09/27/vue-learning-step-by-step-8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="aiolos">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Aiolos">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">【实战篇——第六章】Vue2.5入门到实战开发去哪儿网App——实站环境准备</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-27T10:14:31+08:00">
                2019-09-27
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Vue/" itemprop="url" rel="index">
                    <span itemprop="name">Vue</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：<br>入门视频：《vue2.5入门》 <a href="http://www.imooc.com/learn/980" target="_blank" rel="noopener">http://www.imooc.com/learn/980</a><br>实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 <a href="https://coding.imooc.com/class/chapter/203.html" target="_blank" rel="noopener">https://coding.imooc.com/class/chapter/203.html</a></p>
<p>本文为实战篇的第六章，主要讲解开发去哪儿网App实站环境准备</p>
<p>本文对应官网文档地址：<a href="https://cn.vuejs.org/v2/guide/" target="_blank" rel="noopener">https://cn.vuejs.org/v2/guide/</a></p>
<a id="more"></a>

<h1 id="实站环境准备"><a href="#实站环境准备" class="headerlink" title="实站环境准备"></a>实站环境准备</h1><ol>
<li><p>nodejs、npm、webpack、git<br><img src="/blog/images/20190927125507425.jpg" alt="安装软件"></p>
</li>
<li><p>在码云git创建项目仓库<br><img src="/blog/images/20190927125733996.jpg" alt="创建项目仓库"></p>
</li>
<li><p>配置公钥来关联码云git仓库与本地git<br><img src="/blog/images/20190927130118079.jpg" alt="配置公钥来关联码云git仓库与本地git"></p>
</li>
<li><p>下载码云项目到本地</p>
<figure class="highlight crmsh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 本地进入项目目录，右键git bash</span></span><br><span class="line">git <span class="keyword">clone</span>  <span class="title">git</span>@gitee.com****.git</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过vue-cli在本地创建Vue项目</p>
<figure class="highlight avrasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install -g vue-<span class="keyword">cli</span></span><br><span class="line">vue init webpack 项目名</span><br></pre></td></tr></table></figure>

</li>
</ol>
<p><img src="/blog/images/20190927131201954.jpg" alt="通过vue-cli在本地创建Vue项目"></p>
<ol start="6">
<li>启动项目<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd 项目名</span><br><span class="line">npm <span class="keyword">run</span><span class="bash"> dev</span></span><br></pre></td></tr></table></figure>

</li>
</ol>
<p><img src="/blog/images/20190927131440243.jpg" alt="启动项目"></p>
<ol start="7">
<li>上传本地项目到码云<figure class="highlight dockerfile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git status </span><br><span class="line">git <span class="keyword">add</span><span class="bash"> .</span></span><br><span class="line">git commit -m <span class="string">'project init'</span></span><br><span class="line">git push</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h1 id="项目代码结构"><a href="#项目代码结构" class="headerlink" title="项目代码结构"></a>项目代码结构</h1><p><img src="/blog/images/20190929054501970.jpg" alt="项目代码结构"></p>
<p>package.json //项目需要的第三方依赖<br>package-lock.json //第三方依赖的版本详情<br>index.html //项目默认的首页模板文件<br>.postcssrc //postcss的配置项文件<br>.gitignore //不上传到git仓库的配置<br>.eslintrc //代码规范<br>.eslintignore //不检查的文件<br>.editorconfig //编辑器的配置<br>.babelrc //babel配置<br>static //静态资源文件，如图片、css、模拟的json数据<br>node_modules //项目依赖的包<br>src //项目源代码<br>  main.js //项目的入口文件<br>  app.vue //项目的根组件<br>  router //项目的路由<br>  components //项目的组件<br>  assert //项目的css、js<br> config //项目的配置文件<br> build //项目打包的文件</p>
<blockquote>
<p>开发工作主要是在src下，其他文件基本无需修改</p>
</blockquote>
<h1 id="单文件组件"><a href="#单文件组件" class="headerlink" title="单文件组件"></a>单文件组件</h1><ol>
<li>解析main.js执行流程<blockquote>
<p>a. 在main.js中定义根组件，并绑定到index.html文件中的id=app的dom元素上<br>b. 在根组件中注册并使用App这个局部组件作为模板</p>
</blockquote>
</li>
</ol>
<p><img src="/blog/images/20190929055844938.jpg" alt="解析main.js执行流程"></p>
<ol start="2">
<li>单文件组件<blockquote>
<p>以.vue结尾的文件称为单文件组件，其内部结构如下：</p>
</blockquote>
</li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h1 id="Vue中的路由"><a href="#Vue中的路由" class="headerlink" title="Vue中的路由"></a>Vue中的路由</h1><blockquote>
<p>路由： 就是根据url的不同，返回不同的内容给用户的功能</p>
</blockquote>
<p><strong>router-view标签显示的是当前路由地址所对应的组件内容</strong></p>
<p>Vue中的路由的执行流程：</p>
<blockquote>
<ol>
<li>在组件中引入并注册路由组件router</li>
<li>在页面中通过router-view标签显示url所对应的路由组件的内容</li>
</ol>
</blockquote>
<p><img src="/blog/images/20190929061234843.jpg" alt="Vue中的路由"></p>
<p><strong>如：访问/时，首页通过router-view显示Home组件的内容；访问/list时，首页通过router-view显示List组件的内容</strong></p>
<h1 id="创建项目demo页面"><a href="#创建项目demo页面" class="headerlink" title="创建项目demo页面"></a>创建项目demo页面</h1><blockquote>
<p>新建src/pages/home/Home.vue</p>
</blockquote>
<p><img src="/blog/images/20190929062406951.jpg" alt="实战项目首页"></p>
<h1 id="多页应用VS单页应用"><a href="#多页应用VS单页应用" class="headerlink" title="多页应用VS单页应用"></a>多页应用VS单页应用</h1><ol>
<li>多页应用： 每次访问不同的页面都会请求并返回不同的html页面<br><img src="/blog/images/20190929062817594.jpg" alt="多页应用"></li>
</ol>
<blockquote>
<p>SEO效果好是因为搜索引擎只识别html页面中的内容，不识别JS中的内容</p>
</blockquote>
<ol start="2">
<li>单页应用： 每次访问不同的页面只会进行JS的渲染，不会重新请求和返回新的html页面<blockquote>
<p>JS渲染：直接在当前页面中通过JS来动态清除现有组件内容，再挂载下一页面的组件内容来实现页面不同内容的展示</p>
</blockquote>
</li>
</ol>
<p><img src="/blog/images/20190929063424408.jpg" alt="单页应用"></p>
<blockquote>
<p>单页应用的首屏加载需要发送一次html请求和一次js请求</p>
</blockquote>
<h1 id="项目代码的初始化"><a href="#项目代码的初始化" class="headerlink" title="项目代码的初始化"></a>项目代码的初始化</h1><ol>
<li><p>在index.html中加载移动端特有的meta标签</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;meta <span class="attribute">name</span>=<span class="string">"viewport"</span> <span class="attribute">content</span>=<span class="string">"width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"</span>&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>在main.js中引入reset.css文件</p>
<figure class="highlight xl"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">"./assets/styles/reset.css"</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在main.js中引入border.css来解决移动端的1像素边框的bug</p>
<blockquote>
<p>移动端的1像素边框的bug: 在二倍屏或三倍屏上，1像素的边框会显示成2px或3px</p>
</blockquote>
</li>
<li><p>引入fastclick解决移动端300ms点击延迟的bug</p>
<blockquote>
<p>移动端300ms点击延迟的bug： 移动端的点击事件会延迟300ms才执行<br>a. 安装fastclick到项目依赖中</p>
</blockquote>
</li>
</ol>
<figure class="highlight jboss-cli"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">cd</span> 项目名</span><br><span class="line">npm install fastclick <span class="params">--save</span></span><br><span class="line"><span class="comment"># --save表示开发或者线上发布版本都需要该依赖</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>b. 在main.js中引入fastclick并使用它</p>
</blockquote>
<figure class="highlight coffeescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> fastClick <span class="keyword">from</span> <span class="string">'fastclick'</span></span><br><span class="line"><span class="comment"># 绑定fastclick到body元素上</span></span><br><span class="line">fastClick.attach(<span class="built_in">document</span>.body)</span><br></pre></td></tr></table></figure>

<ol start="5">
<li><p>使用iconfont<br>到iconfont官网中创建项目，如下图：<br><img src="/blog/images/20190929132152629.jpg" alt="到iconfont官网中创建项目"></p>
</li>
<li><p>安装项目将要使用到的其他依赖</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd 项目名</span><br><span class="line">npm <span class="keyword">install</span> stylus <span class="comment">--save</span></span><br><span class="line">npm <span class="keyword">install</span> stylus-loader <span class="comment">--save</span></span><br></pre></td></tr></table></figure></li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Vue哪儿网App实战/" rel="tag"># Vue哪儿网App实战</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/09/25/vue-learning-step-by-step-7/" rel="next" title="【实战篇——第五章】Vue2.5入门到实战开发去哪儿网App——Vue中的动画特效">
                <i class="fa fa-chevron-left"></i> 【实战篇——第五章】Vue2.5入门到实战开发去哪儿网App——Vue中的动画特效
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/09/30/vue-learning-step-by-step-9/" rel="prev" title="【实战篇——第七章】Vue2.5入门到实战开发去哪儿网App——首页开发">
                【实战篇——第七章】Vue2.5入门到实战开发去哪儿网App——首页开发 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">aiolos</p>
              <p class="site-description motion-element" itemprop="description">Java Spring Hadoop 机器学习</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">126</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#实站环境准备"><span class="nav-number">1.</span> <span class="nav-text">实站环境准备</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#项目代码结构"><span class="nav-number">2.</span> <span class="nav-text">项目代码结构</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#单文件组件"><span class="nav-number">3.</span> <span class="nav-text">单文件组件</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Vue中的路由"><span class="nav-number">4.</span> <span class="nav-text">Vue中的路由</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#创建项目demo页面"><span class="nav-number">5.</span> <span class="nav-text">创建项目demo页面</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#多页应用VS单页应用"><span class="nav-number">6.</span> <span class="nav-text">多页应用VS单页应用</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#项目代码的初始化"><span class="nav-number">7.</span> <span class="nav-text">项目代码的初始化</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">aiolos</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
